﻿
@{
    Layout = "~/Views/Shared/_LayoutForEUI.cshtml";
    var OperationList = ViewBag.OperationList as List<SGArchiveSystem7x.Models.CColumnsModel>;
    var listDep = ViewBag.Dep as List<SGArchiveSystem7x.Models.CComboboxModel>;
}
<table id="Operation_Index_grid" class="easyui-datagrid" style="width:100%;" title="运营" data-options="
      rownumbers:true,
       singleSelect:true,
       autoRowHeight:false,
       pagination:true,
       fitColumns:true,
       fit:true,
       striped:true,
       checkOnSelect:true,
       selectOnCheck:true,
       toolbar:'#Operation_Index_tb',
       collapsible:false,
       pageSize: @SGArchiveSystem7x.Models.CCommonsModels.PageSize,
       pageList:[10,15,20]">

    <thead frozen="true">
        <tr>
            @{
                foreach (var c in OperationList)
                {
                    if (c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>

                    }
                }
            }
        </tr>
    </thead>
    <thead>
        <tr>
            @{
                foreach (var c in OperationList)
                {
                    if (!c.Frozen)
                    {
                        <th field="@c.FieldValue" width="@c.Len" align="center" formatter="@c.Formate">@c.FieldText</th>
                    }

                }
            }
        </tr>
    </thead>
</table>
<div id="Operation_Index_tb" style="padding:2px 5px;">
    <input class="easyui-textbox" labelwidth="50px" label="归档号:" style="width:180px" id="Operation_Index_txtcxDH" />
    <select class="easyui-combobox" labelwidth="40px" label="状态:" style="width:180px" id="Operation_Index_cmbcxStatus" editable="false" panelHeight="auto">
        <option value="-1">全部</option>
        <option value="0">我方运营</option>
        <option value="1">乙方运营</option>
        <option value="2">双方运营</option>
    </select>
    <input type="text" class="easyui-datebox" label="起始时间:" labelwidth="60px" style="width:180px" id="Operation_Index_txtSTime" />
    <input type="text" class="easyui-datebox" label="结束时间:" labelwidth="60px" style="width:180px" id="Operation_Index_txtETime" />
    <a href="javascript:void(0);" id="Operation_Index_btnSearch" class="easyui-linkbutton button-blue" onclick="Search()" style="width:110px;height:30px;">查询</a>
    <a href="javascript:void(0);" id="Operation_Index_btnAdd" class="easyui-linkbutton button-blue" onclick="Add()" style="width:110px;height:30px;">添加运营</a>
    <a href="javascript:void(0);" id="Operation_Index_btnRelease" class="easyui-linkbutton button-blue" onclick="Release()" style="width:110px;height:30px;">发布到档案</a>
</div>
<div id="Operation_Index_winOperation" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-save'" minimizable="false" maximizable="false" resizable="false" collapsible="false"
     style="width:500px;height:420px;padding:10px">
    <div style="padding-top:10px">
        <input class="easyui-textbox" labelalign="right" style="width:100%" data-options="required:true,missingMessage:'请输入归档号！'" label="归档号:" id="Operation_Index_txtDH" />
    </div>
    <div style="padding-top:10px">
        <input class="easyui-textbox" labelalign="right" style="width:100%" data-options="required:true,missingMessage:'请输入标题名称！'" label="标题名称:" id="Operation_Index_txtTM" />
    </div>
    @*<div style="padding-top:10px">
            <input class="easyui-textbox" labelalign="right" style="width:100%" data-options="required:true,missingMessage:'请输入创建人！'" label="创建人:" id="Operation_Index_txtTM" />
        </div>*@
    <div style="padding-top:10px">
        <select class="easyui-combobox" labelalign="right" style="width:100%" label="所属部门:" id="Operation_Index_cmbDep" editable="false" panelHeight="auto">
            @{
                foreach (var n in listDep)
                {
                    if (n.ID > -1)
                    {
                        <option value="@n.ID">@n.Text</option>
                    }
                }
            }
        </select>
    </div>
    <div style="padding-top:10px">
        <input class="easyui-datebox" labelalign="right" style="width:100%" label="归档时间:" id="Operation_Index_txtTime" />
    </div>
    <div style="padding-top:10px">
        <select class="easyui-combobox" labelalign="right" style="width:100%" label="状态:" id="Operation_Index_cmbStatus" editable="false" panelHeight="auto">
            <option value="0">我方运营</option>
            <option value="1">乙方运营</option>
            <option value="2">双方运营</option>
        </select>
    </div>

    <input hidden="hidden" id="Operation_Index_txtID" />
    <div data-options="region:'south',border:false" style="text-align:right;padding:0px,0,0;margin-top:20px;">
        <a class="easyui-linkbutton button-blue" onclick="Save_Operation()" data-options="iconCls:'icon-ok'" href="javascript:void(0)" style="width:100px">保存</a>
    </div>
</div>
<div id="Operation_Index_winUpload" title="上传" class="easyui-window" data-options="modal:true,closed:true,iconCls:'icon-save'" minimizable="false" maximizable="false" resizable="false" collapsible="false"
     style="width:500px;height:180px;padding:10px">
    <iframe id="Operation_index_frmMain" frameborder="0" scrolling="auto" width="100%" height="=100%"></iframe>
</div>
<script>
    var arrayDEP = @Html.Raw(Json.Encode(listDep));
    $(function () {

        $('#Operation_Index_grid').datagrid({
            url: '/Operation/Get_ajaxOperationList?dh&stime&etime&status=-1',
            singleSelect: true,
            method: 'post',
            onLoadSuccess: function (data) {
                $('.pagination-page-list').hide();
            }
        });
        InitPagenation();
    })

    //发布到档案
    function Release() {
        var row = $('#Operation_Index_grid').datagrid('getSelected');
        if (row) {
            if (row.YY_STATUS == 2) {
                $.ajax({
                    method: 'post',
                    dataType: 'json',
                    data: { id: row.YY_ID },
                    url: '/Operation/Get_ajaxOperationListId',
                    success: function (data) {
                        $.ajax({
                            method: 'post',
                            dataType: 'Text',
                            data: { dh: data.YY_BH, tm: data.YY_TM, file: data.YY_DZWZ },
                            url: '/Operation/Get_ajaxOperationRelease',
                            success: function (data) {
                                alert(data)
                                if (data == '1')
                                    $.messager.alert('提示', '该运营已发布!', 'warning');
                                else if (data == '2')
                                    $.messager.alert('提示', '发布失败!', 'error');
                                else
                                    $.messager.alert('提示', '发布成功!', 'info');
                            }
                        })
                    }
                })
            }
            else {
                alert('双方未运营！')
            }
        }
        else {
            alert('未选中！')
        }
    }

    //查询
    function Search() {
        var dh = $('#Operation_Index_txtcxDH').val();
        var status = $('#Operation_Index_cmbcxStatus').combobox('getValue');
        var stime = $('#Operation_Index_txtSTime').datebox('getValue');
        var etime = $('#Operation_Index_txtETime').datebox('getValue');
        $('#Operation_Index_grid').datagrid({
            url: '/Operation/Get_ajaxOperationList?dh=' + dh + '&stime=' + stime + '&etime=' + etime + '&status=' + status,
            method: 'post',
        })
    }


    //保存
    function Save_Operation() {
        var id = $('#Operation_Index_txtID').val();
        var dh = $('#Operation_Index_txtDH').val();
        var tm = $('#Operation_Index_txtTM').val();
        var dep = $('#Operation_Index_cmbDep').combobox('getValues');
        var gtime = $('#Operation_Index_txtTime').datebox('getValue');
        var status = $('#Operation_Index_cmbStatus').combobox('getValues');
        var text = $('#Operation_Index_winOperation').panel('options').title;
        if (text == "添加运营") {
            $.ajax({
                method: 'post',
                dataType: 'text',
                data: { dh: dh, tm: tm, dep: dep, gtime: gtime, status: status },
                url: '/Operation/Get_ajaxOperationAdd',
                success: function (data) {
                    if (data == '0')
                        $.messager.alert('提示', '已存在!', 'warning');
                    else if (data == '-1')
                        $.messager.alert('提示', '保存失败!', 'error');
                    else {
                        $.messager.alert('提示', '保存成功!', 'info');

                        $('#Operation_Index_txtDH').textbox("setValue", "");
                        $('#Operation_Index_txtDH').textbox("setValue", "");
                        $('#Operation_Index_txtTM').textbox("setValue", "");

                        $('#Operation_Index_winOperation').window('close');
                        $('#Operation_Index_grid').datagrid('reload');
                    }
                }
            })
        }
        else {
            $.ajax({
                method: 'post',
                dataType: 'text',
                data: { id: id, dh: dh, tm: tm, dep: dep, gtime, status: status },
                url: '/Operation/Get_ajaxOperationModify',
                success: function (data) {
                    if (data == '0')
                        $.messager.alert('提示', '已存在!', 'warning');
                    else if (data == '-1')
                        $.messager.alert('提示', '保存失败!', 'error');
                    else {
                        $.messager.alert('提示', '保存成功!', 'info');

                        $('#Operation_Index_txtDH').textbox("setValue", "");
                        $('#Operation_Index_txtDH').textbox("setValue", "");
                        $('#Operation_Index_txtTM').textbox("setValue", "");

                        $('#Operation_Index_winOperation').window('close');
                        $('#Operation_Index_grid').datagrid('reload');
                    }
                }
            })
        }
    }

    ///初始化分页
    function InitPagenation() {
        //设置分页控件
        var p = $('#Operation_Index_grid').datagrid('getPager');
        $(p).pagination({
            onSelectPage: function (pageNumber, pageSize) {
                SearchPager(pageNumber, pageSize);
            }
        })
    }
    //调用分页方法
    function SearchPager(num, size) {

        $('#Operation_Index_grid').datagrid('options').url = '/Operation/Get_ajaxOperationListPager?num=' + num +
            '&size=' + size;
        $('#Operation_Index_grid').datagrid('reload');
        $('#Operation_Index_grid').datagrid('options').pageNumber = num;
        $('#Operation_Index_grid').datagrid('options').pageSize = size;
    }

    function Add() {
        $('#Operation_Index_winOperation').window({
            title: '添加运营',
            closed: false
        });
    }

    //查看pdf
    function showPdf(id) {

    }

    function Edit(id) {
        $.ajax({
            method: 'post',
            dataType: 'json',
            data: { id: id },
            url: '/Operation/Get_ajaxOperationListId',
            success: function (data) {
                $('#Operation_Index_txtID').val(data.YY_ID);
                $("#Operation_Index_txtDH").textbox('setValue', data.YY_BH);
                $("#Operation_Index_txtTM").textbox('setValue', data.YY_TM);
                $("#Operation_Index_cmbDep").combobox('setValue', data.YY_DEPID);
                $("#Operation_Index_txtTime").datebox('setValue', data.YY_DATE);
                $('#Operation_Index_cmbStatus').combobox('setValues', data.YY_STATUS);

            }
        })
        $('#Operation_Index_winOperation').window({
            title: '修改运营',
            closed: false,
        });
    }
    function Upload(id) {
        $('#Operation_Index_winUpload').window('open');
        document.getElementById('Operation_index_frmMain').src = '/Operation/UploadIndex?id=' + id
    }
    function formatDEP(value, row) {
        for (var i = 0; i < arrayDEP.length; i++) {
            if (arrayDEP[i].ID == value) {
                return arrayDEP[i].Text;
            }
        }
        return -1;
    }

    //上传电子文件
    function formatUpload(value, row) {
        var id = row.YY_ID;
        return "<a href='javascript:void(0)' onclick='Upload(" + id + ")'><img src='../Content/images/AddToAlbum.png' heigth='16px' width='16px'></img>上传</a>";
    }
    function Del(id) {
        $.messager.confirm("提示", "确定要删除吗?", function (r) {
            if (r) {
                $.ajax({
                    method: "post",
                    dataType: "text",
                    url: "/Operation/Get_ajaxOperationDel",
                    data: { id: id },
                    success: function (data) {
                        if (data == "1") {
                            $.messager.alert("提示", "删除成功!", "info");
                            $('#Operation_Index_grid').datagrid('reload');
                        } else
                            $.messager.alert("提示", "删除失败!", "error");
                    }
                })
            }
        })
    }

    //电子文件
    function formatFile(value, row) {
        if (value == null || value == '')
            return "";
        var id = row.YY_ID;
        return "<a href='javascript:void(0)' onclick='showPdf(" + id + " )'><img src='../Content/images/images.png'></img></a>";
    }
    //删除
    function formatDel(value, row) {
        var id = row.YY_ID;
        return "<a href='javascript:void(0)' onclick='Del(" + id + " )'><img src='../Content/images/close.png'></img>删除</a>";
    }
    //修改
    function formatEdit(value, row) {
        var id = row.YY_ID;
        return "<a href='javascript:void(0)' onclick='Edit(" + id + " )'><img src='../Content/images/edit.png'></img>编辑</a>";
    }

    //运营状态
    function formatStatus(value, row) {
        if (value == 0)
            return "我方运营";
        if (value == 1)
            return "乙方运营";
        if (value == 2)
            return "双方运营";
    }
    //时间
    function formatDate(value, row) {
        if (value != null) {
            var time = new Date(parseInt(value.substr(6, 19)))
            return time.getFullYear() + "-" + (time.getMonth() + 1) + "-" + time.getDate() + " " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();
        }
        else {
            return "";
        }
    }
</script>

